/***************************************************************************************************
  *Copyright(C),2010-2016,Sumscope
  *FileName	:  scoped_pointer.h
  *Author	:  scofined.qi
  *Version	:  1.0
  *Date		:  2015/12/18
  *Desc		:  //用于主要说明此程序文件完成的主要功能
  *Relation :  
  *Others	:  //其他内容说明
  *Function :  //主要函数列表，每条记录应包含函数名及功能简要说明
  *History	:  //修改历史记录列表，每条修改记录应包含修改日期、修改者及修改内容简介
***************************************************************************************************/
#pragma once

namespace qb{
namespace base{
	template<class T>
    class ScopedPtr{
		T*	m_ptr;
	public:
		ScopedPtr(T* ptr):m_ptr(ptr){}
		~ScopedPtr()
		{
			if(m_ptr)
			{
				delete m_ptr;
			}
		}
		bool operator!(){return m_ptr==0;}
		T* operator->(){return m_ptr;}
		T& operator*(){return *m_ptr;}
		T* operator&(){return m_ptr;}
		operator bool(){return m_ptr!=0;}
	};

	template<class T>
    class ScopedPtr2{
		T	m_ptr;
	public:
		ScopedPtr2(T ptr):m_ptr(ptr){}
		~ScopedPtr2()
		{
			if(m_ptr)
			{
				delete m_ptr;
			}
		}
		bool operator!(){return m_ptr==0;}
		T operator->(){return m_ptr;}
		operator bool(){return m_ptr!=0;}
	};

	template<class T>
    class ScopedArrayPtr{
		T*		m_ptr;
		int		m_length;
	public:
		ScopedArrayPtr(int len) :m_length(len){
			m_ptr = new T[len];
			memset(m_ptr, 0, sizeof(T)*len);
		}
		~ScopedArrayPtr()
		{
			if (m_ptr)
			{
				delete []m_ptr;
			}
		}
		int length()const{return m_length; }
		bool operator!(){ return m_ptr == 0; }
		T* operator->(){ return m_ptr; }
		T& operator*(){ return *m_ptr; }
		T* operator&(){ return m_ptr; }
		operator bool(){ return m_ptr != 0; }
		operator T*(){ return m_ptr; }
		T* getptr(){ return m_ptr; }
	};
}//namespace base;
}//namespace qb;
